var express = require('express');
var app = express();

//需要在各自的环境运行
if (app.get('env') === 'development'){
    //开发环境 export NODE_ENV=development
    filename = '/root/logs/node-h5-active/log'
}else if (app.get('env') === 'production'){
    // 生产环境 export NODE_ENV=production
    filename = '/root/logs/node-h5-active/log'
}else if (app.get('env') === 'localhost'){
    // 本地 export NODE_ENV=localhost
    filename = '../logs/node-h5-active/log'
}

var log4js = require('log4js');

log4js.configure({
    appenders: [
        {
            type: 'console',
            category: "console"
        }, //控制台输出
        {
            category: 'infoLog',
            type: "dateFile",
            encoding: 'UTF-8',
            filename: filename,
            alwaysIncludePattern: true,
            pattern: "-info-yyyy-MM-dd.log",
        },//日期文件格式
        {
            category:"errorLog",
            type: "file",
            encoding: 'UTF-8',
            filename: filename+'-error.log',
            maxLogSize:10480000, //10Mb
            backups:20
        }
    ],
    replaceConsole: true,   //替换console.log
    levels:{
        console: 'ALL',
        infoLog: 'info',
        errorLog: 'error'
    }
});

var infoLog = log4js.getLogger('infoLog');
var errorLog = log4js.getLogger('errorLog');
exports.logger = infoLog;
exports.logger_error = errorLog;
